using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Template : Admin, IRequiresSessionState
{
	protected Literal TemplateTitle;
	protected Literal EditTemplateTitle;
	protected Literal TemPath;
	protected Literal TemplateFileName;
	protected TextBox TemplateName;
	protected Literal TemNameMsg;
	protected TextBox TemplateContent;
	protected DropDownList LabelClassSelect;
	protected Literal LabelList;
	protected DropDownList PageLabelClassSelect;
	protected Literal PageLabelList;
	protected Literal SysLabell;
	protected RequiredFieldValidator rfv1;
	protected Button ButViewModify;
	protected Button SaveTemplateButton;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindPage();
			this.BindLabel();
			this.BindPageLabel("");
			this.BingSysLabel();
			LabelBll labelBll = new LabelBll();
			DataTable labelType = labelBll.GetLabelType();
			this.LabelClassSelect.DataSource = labelType;
			this.LabelClassSelect.DataTextField = "Type";
			this.LabelClassSelect.DataValueField = "Type";
			this.LabelClassSelect.DataBind();
			PageLabelBll pageLabelBll = new PageLabelBll();
			DataTable pageLabelType = pageLabelBll.GetPageLabelType();
			this.PageLabelClassSelect.DataSource = pageLabelType;
			this.PageLabelClassSelect.DataTextField = "Type";
			this.PageLabelClassSelect.DataValueField = "Type";
			this.PageLabelClassSelect.DataBind();
		}
		this.TemplateContent.Attributes.Add("onmouseup", "dragend();");
		this.TemplateContent.Attributes.Add("onmousemove", "movePoint();");
	}
	protected void BingSysLabel()
	{
		Literal expr_07 = this.SysLabell;
		expr_07.Text = expr_07.Text + "<div onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"ShowProduct\">商品列表标签</div>" + Environment.NewLine;
		Literal expr_28 = this.SysLabell;
		expr_28.Text = expr_28.Text + "<div onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"ShowShop\">店铺列表标签</div>" + Environment.NewLine;
		Literal expr_49 = this.SysLabell;
		expr_49.Text = expr_49.Text + "<div onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"ShowArticle\">文章列表标签</div>" + Environment.NewLine;
		Literal expr_6A = this.SysLabell;
		expr_6A.Text = expr_6A.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"SiteName\">网站名称</div>" + Environment.NewLine;
		Literal expr_8B = this.SysLabell;
		expr_8B.Text = expr_8B.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"Logo\">网点Logo</div>" + Environment.NewLine;
		Literal expr_AC = this.SysLabell;
		expr_AC.Text = expr_AC.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"InstallDir\">站点安装路径</div>" + Environment.NewLine;
		Literal expr_CD = this.SysLabell;
		expr_CD.Text = expr_CD.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"Banner\">网点Banner</div>" + Environment.NewLine;
		Literal expr_EE = this.SysLabell;
		expr_EE.Text = expr_EE.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"WebMaster\">站长名</div>" + Environment.NewLine;
		Literal expr_10F = this.SysLabell;
		expr_10F.Text = expr_10F.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"WebMasterEmail\">站长名Email</div>" + Environment.NewLine;
		Literal expr_130 = this.SysLabell;
		expr_130.Text = expr_130.Text + "<div onclick=\"cit()\" onmousedown=\"dit(3)\" class=\"label_square\" value=\"DefaultCss\">网站样式</div>" + Environment.NewLine;
		Literal expr_151 = this.SysLabell;
		expr_151.Text = expr_151.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"SiteUrl\">网站Url</div>" + Environment.NewLine;
		Literal expr_172 = this.SysLabell;
		expr_172.Text = expr_172.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"PageTitle\">当前页面标题</div>" + Environment.NewLine;
		Literal expr_193 = this.SysLabell;
		expr_193.Text = expr_193.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"UserCookies\">曾经登录用户名</div>" + Environment.NewLine;
		Literal expr_1B4 = this.SysLabell;
		expr_1B4.Text = expr_1B4.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"LogingUserName\">当前登录用户名</div>" + Environment.NewLine;
		Literal expr_1D5 = this.SysLabell;
		expr_1D5.Text = expr_1D5.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"LogingUserID\">当前登录用户ID</div>" + Environment.NewLine;
		Literal expr_1F6 = this.SysLabell;
		expr_1F6.Text = expr_1F6.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"TemplateDir\">当前模板目录</div>" + Environment.NewLine;
		Literal expr_217 = this.SysLabell;
		expr_217.Text = expr_217.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"SkinDir\">当前风格目录</div>" + Environment.NewLine;
		Literal expr_238 = this.SysLabell;
		expr_238.Text = expr_238.Text + "<div onclick=\"cit()\" onmousedown=\"dit(0)\" class=\"label_square\" value=\"CopyRight\">版权信息</div>" + Environment.NewLine;
	}
	protected void BindPage()
	{
		if (base.Request["action"] != null)
		{
			if (base.Request["Dir"] != null)
			{
				string onClientClick = this.ButViewModify.OnClientClick;
				this.ButViewModify.OnClientClick = string.Format(onClientClick, base.Server.UrlEncode(base.Request["Dir"]));
				string str = this.config["TemplateDir"].ToString().Replace("/", "\\");
				string text = base.Request["action"];
				if (text != null)
				{
					if (!(text == "add"))
					{
						if (text == "modify")
						{
							this.TemplateFileName.Visible = true;
							this.TemplateName.Visible = false;
							this.TemNameMsg.Visible = false;
							this.rfv1.Visible = false;
							this.TemPath.Visible = false;
							this.TemplateTitle.Visible = false;
							this.EditTemplateTitle.Visible = true;
							string text2 = base.Request["Dir"];
							this.TemplateFileName.Text = text2;
							string truePath = Fetch.GetTruePath(str + text2);
							FileIO fileIO = new FileIO();
							try
							{
								this.TemplateContent.Text = fileIO.ReadFromFile(truePath);
							}
							catch (Exception ex)
							{
								this.WriteErrMsg("", Language.GetAdminMsg("Template/ReadTemErr", ex.Message.ToString()), "");
							}
						}
					}
					else
					{
						this.TemplateFileName.Visible = false;
						this.TemplateTitle.Visible = true;
						this.EditTemplateTitle.Visible = false;
						this.TemPath.Text = base.Request["Dir"].Replace("\\", "/");
						this.TemplateContent.Text = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
						TextBox expr_13A = this.TemplateContent;
						expr_13A.Text += "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
						TextBox expr_156 = this.TemplateContent;
						expr_156.Text += "<head runat=\"server\">\n";
						TextBox expr_172 = this.TemplateContent;
						expr_172.Text += "<title>新建模板文档</title>\n";
						TextBox expr_18E = this.TemplateContent;
						expr_18E.Text += "</head>\n\n";
						TextBox expr_1AA = this.TemplateContent;
						expr_1AA.Text += "<body>\n";
						TextBox expr_1C6 = this.TemplateContent;
						expr_1C6.Text += "<form id=\"form_9\" runat=\"server\">\n\n\n";
						TextBox expr_1E2 = this.TemplateContent;
						expr_1E2.Text += "     请在这里输入模板的内容\n\n";
						TextBox expr_1FE = this.TemplateContent;
						expr_1FE.Text += "</form>\n";
						TextBox expr_21A = this.TemplateContent;
						expr_21A.Text += "</body>\n";
						TextBox expr_236 = this.TemplateContent;
						expr_236.Text += "</html>\n";
					}
				}
			}
			else
			{
				this.WriteErrMsg("", Language.Get("Common/LostParam", "Dir"), "");
			}
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "action"), "");
		}
	}
	protected void BindPageLabel_Change(object sender, EventArgs e)
	{
		if (this.LabelClassSelect.SelectedValue == "全部分页标签")
		{
			this.BindPageLabel("");
		}
		else
		{
			this.BindPageLabel(this.PageLabelClassSelect.SelectedValue);
		}
	}
	protected void BindPageLabel(string PageLabelType)
	{
		PageLabelBll pageLabelBll = new PageLabelBll();
		DataTable pageLabelByType = pageLabelBll.GetPageLabelByType(PageLabelType);
		if (pageLabelByType.Rows.Count > 0)
		{
			this.PageLabelList.Text = "";
			foreach (DataRow dataRow in pageLabelByType.Rows)
			{
				Literal expr_5F = this.PageLabelList;
				string text = expr_5F.Text;
				expr_5F.Text = string.Concat(new string[]
				{
					text,
					"<div onclick=\"cit()\" onmousedown=\"dit(2)\" class=\"label_square\" title=\"",
					dataRow["Name"].ToString(),
					"\" value=\"",
					dataRow["Name"].ToString(),
					"\">"
				});
				if (dataRow["Name"].ToString().Length > 8)
				{
					Literal expr_109 = this.PageLabelList;
					expr_109.Text += dataRow["Name"].ToString().Substring(0, 8);
				}
				else
				{
					Literal expr_13F = this.PageLabelList;
					expr_13F.Text += dataRow["Name"].ToString();
				}
				Literal expr_168 = this.PageLabelList;
				expr_168.Text = expr_168.Text + "</div>" + Environment.NewLine;
			}
		}
	}
	protected void BindLabel()
	{
		LabelBll labelBll = new LabelBll();
		DataTable labelByType = labelBll.GetLabelByType("");
		if (labelByType.Rows.Count > 0)
		{
			foreach (DataRow dataRow in labelByType.Rows)
			{
				Literal expr_52 = this.LabelList;
				string text = expr_52.Text;
				expr_52.Text = string.Concat(new string[]
				{
					text,
					"<div title=\"",
					dataRow["Name"].ToString(),
					"\" onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"",
					dataRow["Name"].ToString(),
					"\">"
				});
				if (dataRow["Name"].ToString().Length > 8)
				{
					Literal expr_FC = this.LabelList;
					expr_FC.Text += dataRow["Name"].ToString().Substring(0, 8);
				}
				else
				{
					Literal expr_132 = this.LabelList;
					expr_132.Text += dataRow["Name"].ToString();
				}
				Literal expr_15B = this.LabelList;
				expr_15B.Text = expr_15B.Text + "</div>" + Environment.NewLine;
			}
		}
	}
	protected void select_LabelClassSelect(object sender, EventArgs e)
	{
		this.LabelList.Text = "";
		LabelBll labelBll = new LabelBll();
		DataTable labelByType;
		if (this.LabelClassSelect.SelectedValue == "全部标签")
		{
			labelByType = labelBll.GetLabelByType("");
		}
		else
		{
			labelByType = labelBll.GetLabelByType(this.LabelClassSelect.SelectedValue);
		}
		if (labelByType.Rows.Count > 0)
		{
			foreach (DataRow dataRow in labelByType.Rows)
			{
				Literal expr_9D = this.LabelList;
				expr_9D.Text = expr_9D.Text + "<div onclick=\"cit()\" onmousedown=\"dit(1)\" class=\"label_square\" value=\"" + dataRow["Name"].ToString() + "\">";
				if (dataRow["Name"].ToString().Length > 8)
				{
					Literal expr_F3 = this.LabelList;
					expr_F3.Text += dataRow["Name"].ToString().Substring(0, 8);
				}
				else
				{
					Literal expr_129 = this.LabelList;
					expr_129.Text += dataRow["Name"].ToString();
				}
				Literal expr_152 = this.LabelList;
				expr_152.Text = expr_152.Text + "</div>" + Environment.NewLine;
			}
		}
	}
	protected void SaveTemplateButton_Click(object sender, EventArgs e)
	{
		FileIO fileIO = new FileIO();
		string text = this.config["TemplateDir"].ToString().Replace("/", "\\");
		if (base.Request["action"] != null)
		{
			if (base.Request["Dir"] != null)
			{
				string text2 = base.Request["action"];
				if (text2 != null)
				{
					if (!(text2 == "add"))
					{
						if (text2 == "modify")
						{
							string text3 = this.TemplateContent.Text;
							string text4 = this.TemplateFileName.Text.Replace("/", "\\");
							string text5 = text4.Substring(0, text4.LastIndexOf("\\"));
							string truePath = Fetch.GetTruePath(text + "\\" + text4);
							try
							{
								fileIO.CreateTemplateFile(text3, truePath);
							}
							catch (Exception ex)
							{
								this.WriteErrMsg("", Language.GetAdminMsg("Template/SaveTemErr", ex.Message.ToString()), "");
							}
							this.WriteSuccessMsg("", Language.GetAdminMsg("Template/SaveTemSuccess"), "Admin_ManageTemplate.aspx");
						}
					}
					else
					{
						string text3 = this.TemplateContent.Text;
						string text6 = this.TemplateName.Text;
						if (string.IsNullOrEmpty(text6))
						{
							this.WriteErrMsg("", Language.GetAdminMsg("Template/TemFileNameErr"), "");
						}
						text6 += ".html";
						string truePath = Fetch.GetTruePath(string.Concat(new string[]
						{
							text,
							"\\",
							this.TemPath.Text.Replace("/", "\\"),
							"\\",
							text6
						}));
						try
						{
							fileIO.CreateTemplateFile(text3, truePath);
						}
						catch (Exception ex)
						{
							this.WriteErrMsg("", Language.GetAdminMsg("Template/SaveTemErr", ex.Message.ToString()), "");
						}
						this.WriteSuccessMsg("", Language.GetAdminMsg("Template/SaveTemSuccess"), "Admin_ManageTemplate.aspx?Dir=" + base.Server.UrlEncode(this.TemPath.Text.Replace("\\", "/")));
					}
				}
			}
			else
			{
				this.WriteErrMsg("", Language.Get("Common/LostParam", "Dir"), "");
			}
		}
		else
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "action"), "");
		}
	}
}
